#include "piece_horse.hpp"

bool Piece_Horse::move(const Coordinate &goal){
	Coordinate spacing = goal - coor;
	if (spacing * spacing == 5){
		if (!pieces[gameMap[coor + spacing / 2]]->isLife()){
			if (pieces[gameMap[goal]]->isLife()) {
                              if (pieces[gameMap[goal]]->getColor() != color)
                                  pieces[gameMap[goal]]->setLife(false);
                              else
                                  return false;
                        }
			updateCoor(gameMap, goal);
			return true;
		}
	}
	return false;
}

void Piece_Horse::init(){
	switch (pt){
		case PieceType::RED_HORSE1:
			coor.x = 9;
			coor.y = 1;
                        color = RED;
			break;
		case PieceType::RED_HORSE2:
			coor.x = 9;
			coor.y = 7;
                        color = RED;
			break;
		case PieceType::BLACK_HORSE1:
			coor.x = 0;
			coor.y = 7;
                        color = BLACK;
			break;
		case PieceType::BLACK_HORSE2:
			coor.x = 0;
			coor.y = 1;
                        color = BLACK;
			break;
		default:
			break;
	}
	life = true;
}

Piece_Horse::~Piece_Horse(){}
